#include "InterestRateBondChart.h"
#include "../StringResource.h"
#include <core/StyleMgr.h>
#include <core/ImageMgr.h>
#include <core/Utility.h>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMouseEvent>
#include <widgets/chart/basechart_plot.h>
#include <widgets/chart/basechart_graph.h>
#include <widgets/chart/basechart_bars.h>
#include <widgets/chart/basechart_base.h>
#include <bondlib/BondContainer.h>
#include <bondlib/BondAuctionInfo.h>
#include <widgets/STips.h>
#include <qbtools/tools.h>

using namespace qb;

QColor clrBarLastWeekNormal = QColor(0, 96, 255,153); //上周柱体颜色60%
QColor clrBarLastWeekHover = QColor(0, 96, 255,216); //上周柱体颜色85%
QColor clrBarThisWeekNormal = QColor(35, 188, 120,153); //本周柱体颜色60%
QColor clrBarThisWeekHover = QColor(35, 188, 120,216); //本周柱体颜色85%
QColor clrBarNextweek = QColor(255, 91, 0, 51);  //下周柱体填充色20%
QColor clrBarNextweekNormal = QColor(255, 91, 0, 153);  //下周柱体边框的颜色60%
QColor clrBarNextweekHover = QColor(255, 91, 0, 216);  //下周柱体边框的颜色80%
QColor clrBackIntervalHover = QColor(19, 108, 94, 77);  //高亮柱体后面背景色30%

QColor clrBarLastMonthNormal = QColor(152, 118, 44, 255); //上月柱体颜色
QColor clrBarThisMonthNormal = QColor(74, 44, 152, 255); //本月柱体颜色
QColor clrBarNextMonthNormal = QColor(75, 108, 69, 255);  //下月柱体边框的颜色

InterestRateBondChart::InterestRateBondChart(QWidget* p)
	: QWidget(p)
{
	QVBoxLayout* mainLayout = new QVBoxLayout(this);
	mainLayout->setContentsMargins(0, 0, 0, 0);
	customPlot = new BaseChartCustomPlot(this);
	mainLayout->addWidget(customPlot);
	setLayout(mainLayout);

	QBrush boxBrush(StyleMgr::instance().color("BasicPlate"));
	customPlot->setBackground(boxBrush);
	
	BaseChartBars* lastBar = new BaseChartBars(customPlot->xAxis, customPlot->yAxis);
	BaseChartBars* thisBar = new BaseChartBars(customPlot->xAxis, customPlot->yAxis);
	BaseChartBars* nextBar = new BaseChartBars(customPlot->xAxis, customPlot->yAxis);
	
	lastBar->setAntialiased(false);
	thisBar->setAntialiased(false);
	nextBar->setAntialiased(false);

	lastBar->setName("Last");
	thisBar->setName("this");
	nextBar->setName("Next");

	lastBar->setLight(216);
	nextBar->setLight(153);
	thisBar->setLight(216);

	QVector<double> ticks1;
	QVector<QString> labels1;
	ticks1 << 1 << 2 << 3 << 4 << 5 << 6 ;
	labels1 << tr("国债") << tr("国开") << tr("口行") << tr("农发") << tr("地方债") << tr("总供给");

	QSharedPointer<BaseChartAxisTickerText> textTicker1(new BaseChartAxisTickerText);
	textTicker1->addTicks(ticks1, labels1);
	customPlot->xAxis->setTicker(textTicker1);
	customPlot->xAxis->setSubTicks(false);
	customPlot->xAxis->setTickLength(0, 4);
	customPlot->xAxis->setRange(0, 7);
	customPlot->xAxis->setBasePen(QPen(QColor(38, 55, 53)));
	customPlot->xAxis->setTickPen(QPen(QColor(23, 36, 34)));
	customPlot->xAxis->grid()->setVisible(true);
	customPlot->xAxis->grid()->setPen(QPen(QColor(38, 55, 53), 0, Qt::SolidLine));
	customPlot->xAxis->setTickLabelColor(QColor(130, 130, 130));

	customPlot->yAxis->setBasePen(QPen(QColor(23, 36, 34)));
	customPlot->yAxis->setTickPen(QPen(QColor(23, 36, 34)));
	customPlot->yAxis->setSubTickPen(QPen(QColor(23, 36, 34)));
	customPlot->yAxis->setTickLabelPadding(40);
	customPlot->yAxis->grid()->setCustomAxisGrid(this);
	customPlot->yAxis->setCustomGrid();
	customPlot->yAxis->setTickLabelColor(QColor(130, 130, 130));
	customPlot->yAxis->grid()->setPen(QPen(QColor(38, 55, 53), 0, Qt::SolidLine));

	m_barsGroup = new BaseChartBarsGroup(customPlot);
	QList<BaseChartBars*> bars;
	bars << lastBar << thisBar << nextBar;
	foreach(BaseChartBars * bar, bars) {
		// 设置柱状图的宽度类型为以key坐标轴计算宽度的大小，其实默认就是这种方式
		bar->setWidthType(BaseChartBars::wtPlotCoords);
		bar->setWidth(bar->width() / bars.size()); // 设置柱状图的宽度大小
		m_barsGroup->append(bar);  // 将柱状图加入柱状图分组中
	}
	m_barsGroup->setSpacingType(BaseChartBarsGroup::stAbsolute);  // 设置组内柱状图的间距，按像素
	m_barsGroup->setSpacing(0);     // 设置较小的间距值，这样看起来更紧凑

	m_textElement = new BaseChartTextElement(customPlot,
		NewStringTable::strFixedIncomeGovBondIssuance(0), QFont("Microsoft YaHei", 9, QFont::Bold));
	m_textElement->setText(NewStringTable::strFixedIncomeGovBondIssuance(0), NewStringTable::strFixedIncomeGovBondIssuance(1), NewStringTable::strFixedIncomeGovBondIssuance(2));
	m_textElement->setCustomDraw(this);
	m_textElement->setTextFlags(Qt::AlignLeft | Qt::AlignVCenter);
	m_textElement->setTextOffset(20);
	m_textElement->setTextColor(StyleMgr::instance().color("TextNormal"));
	customPlot->plotLayout()->addElement(1, 0, m_textElement);

	connect(customPlot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(click(QMouseEvent*)));
	connect(customPlot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(hover(QMouseEvent*)));
}

void InterestRateBondChart::setDate(int dateType, std::map<int, CRateBondList>* FIGovtBondIssuance) {
	int offset = (dateType == DATE_WEEK) ? 0 : 3;
	m_week = (dateType == DATE_WEEK);
	m_textElement->setText(NewStringTable::strFixedIncomeGovBondIssuance(0+ offset), NewStringTable::strFixedIncomeGovBondIssuance(1 + offset), NewStringTable::strFixedIncomeGovBondIssuance(2 + offset));
	
	//先做完全清空处理
	initListMap();
	//按照上周、本周、下周分别统计不同债券类型的发行量
	getDistributionData(FIGovtBondIssuance, m_data);

	refresh(dateType);
	
	setRange();

	if (!m_week)
	{
		m_barsGroup->bars(0)->setLight(-1);
		m_barsGroup->bars(1)->setLight(-1);
		m_barsGroup->bars(2)->setLight(-1);
	}

	customPlot->replot();
}

bool InterestRateBondChart::customDraw(BaseChartPainter* painter, const QRect& rect)
{
	QColor clr[3];
	clr[0] = m_lenendInfo[0].isShow ? (m_week ? clrBarLastWeekNormal : clrBarLastMonthNormal) : QColor(112, 111, 103);
	clr[1] = m_lenendInfo[1].isShow ? (m_week ? clrBarThisWeekNormal : clrBarThisMonthNormal) : QColor(112, 111, 103);
	clr[2] = m_lenendInfo[2].isShow ? (m_week ? clrBarNextweekNormal : clrBarNextMonthNormal) : QColor(112, 111, 103);
	customDraw(painter, rect, 3, clr);
	return true;
}

void InterestRateBondChart::customDraw(BaseChartPainter* painter, const QRect& rect, int count, QColor* clr)
{
	QRect rectBK = rect;
	QRect rectEX = rect;

	for (int i = 0; i < count; i++)
	{
		if (i == 0)
		{
			rectBK.setLeft(rect.left());
		}
		else
		{
			rectBK.setLeft(rect.left() + i * rect.width() / count + 2);
		}

		if (i == count - 1)
		{
			rectBK.setRight(rect.right());
		}
		else
		{
			rectBK.setRight(rectBK.left() + rect.width() / count - 2);
		}
		rectEX.setLeft(rectBK.left() + 6);
		rectEX.setRight(rectBK.left() + 14);
		rectEX.setTop(rectBK.top() + rectBK.height() / 2 - 4);
		rectEX.setBottom(rectBK.top() + rectBK.height() / 2 + 4);

		m_lenendInfo[i].rect = rectBK;

		painter->fillRect(rectBK, QColor(38, 55, 53));
		painter->setPen(clr[i]);
		if (i == 2 && m_week)
		{
			painter->setPen(QPen(clr[i], 1, Qt::DashLine));
		}

		painter->setBrush(clr[i]);
		painter->drawRect(rectEX);
	}
}

void InterestRateBondChart::paintEvent(QPaintEvent* event)
{
	QStylePainter painter(this);
	painter.fillRect(rect(), StyleMgr::instance().color("BasicPlate"));
}

void InterestRateBondChart::mousePressEvent(QMouseEvent* event)
{
	QPoint mousePos = event->pos();
}

void InterestRateBondChart::mouseMoveEvent(QMouseEvent* event)
{
	QPoint mousePos = event->pos();
}

bool InterestRateBondChart::drawGridYLines(BaseChartPainter* painter)
{ 
	QString szValue;
	QRectF rfText;
	int nTextTop = 10000;//纵轴刻度文字
	int top = customPlot->yAxis->axisRect()->top();
	int bottom = customPlot->yAxis->axisRect()->bottom();
	int tickCount = (customPlot->yAxis->ticker()->tickCount() == 0 ? 5 : customPlot->yAxis->ticker()->tickCount());
	double step = (customPlot->yAxis->range().upper - customPlot->yAxis->range().lower) / tickCount; //待修改要改成最大值-最小值，需通过设置传参
	QRectF rect(0, 0, 10000, 10000);
	int nFlag = Qt::TextDontClip | Qt::AlignLeft | Qt::AlignVCenter;
	int i = 0;

	while (1) {
		float price = 0 + step * i;
		int Y = customPlot->yAxis->coordToPixel(price);
		if (Y < top - 1 || Y > bottom) break;
		if (Y <= bottom)
		{
			painter->drawLine(QLineF(customPlot->xAxis->axisRect()->left() - customPlot->yAxis->tickLabelPadding(), Y, customPlot->xAxis->axisRect()->right(), Y));

			szValue = QString("%1").arg(price, 0, 'f', 0, '0');
			if (i == tickCount)
			{
				szValue.append(tr("(亿)"));
			}

			if (szValue.length() > 0)
			{
				QRectF measureRect = painter->boundingRect(rect, nFlag, szValue);
				if (nTextTop > Y + measureRect.height()) {
					QPen oldPen = painter->pen();
					painter->setPen(QColor(128, 128, 128, 255));
					painter->drawText(customPlot->xAxis->axisRect()->left() - customPlot->yAxis->tickLabelPadding() + 2, Y - measureRect.height(), measureRect.width(), measureRect.height(), nFlag, szValue);
					painter->setPen(oldPen);
					nTextTop = Y - measureRect.height();
				}
			}
		}
		i++;
		if (i > 100)
			break;
	}

	painter->drawLine(QLineF(customPlot->xAxis->axisRect()->left() - customPlot->yAxis->tickLabelPadding(), top, customPlot->xAxis->axisRect()->right(), top));

	return true;
}

void InterestRateBondChart::click(QMouseEvent* event)
{
	if (event->button() == Qt::LeftButton)
	{
		QPoint mousePos = event->pos();

		for (int i = 0; i < 3; i++)
		{
			if (m_lenendInfo[i].rect.contains(mousePos))
			{
				if (m_lenendInfo[i].isShow)
				{
					m_lenendInfo[i].isShow = false;
					QVector<double> ticks1;
					QVector<double> data;
					ticks1 << 1 << 2 << 3 << 4 << 5 << 6;
					data << 0 << 0 << 0 << 0 << 0 << 0;
					m_barsGroup->bars(i)->setData(ticks1, data);
				}
				else
				{
					m_lenendInfo[i].isShow = true;
					QVector<double> ticks1;
					QVector<double> data;
					ticks1 << 1 << 2 << 3 << 4 << 5 << 6;
					data << m_data.m_Map[0].m_countArray[i] << m_data.m_Map[1].m_countArray[i] << m_data.m_Map[2].m_countArray[i] << m_data.m_Map[3].m_countArray[i] << m_data.m_Map[4].m_countArray[i] << m_data.m_Map[5].m_countArray[i] ;
					m_barsGroup->bars(i)->setData(ticks1, data);
				}

			}
		}
		setRange();
		customPlot->replot();
	}
	else if (event->button() == Qt::RightButton)
	{
		//增加tips：另存为
		QMenu* menu = new QMenu();
		QAction* aboutQB = new QAction("另存为", this);
		menu->addAction(aboutQB);

		menu->setStyleSheet(QString(
			"QMenu::item {padding:6px 38px 6px 18px;}\n"
			"QMenu::item:hover {background-color:#%2;}\n"
			"QMenu::item:disabled {color:#%3;}\n"
			"QMenu {background-color:#%4; margin:0px;font:12px Microsoft YaHei;font-weight:bold;}\n"
			"QMenu::separator{height:1px; background:#%5; margin-left:0px; margin-right:0px;}\n"
			"QMenu::item:default { color: #%6; }")
			.arg(NAME_COLOR("Hover").rgb(), 0, 16)
			.arg(NAME_COLOR("SupportingWord").rgb(), 0, 16)
			.arg(NAME_COLOR("ElementBackground").rgb(), 0, 16)
			.arg(NAME_COLOR("PartPlate").rgb(), 0, 16)
			.arg(NAME_COLOR("Up_Increase_H1").rgb(), 0, 16));
		menu->exec(QCursor::pos());
		//return;
	}
}

void InterestRateBondChart::hover(QMouseEvent* event)
{
	
	bool isShow = false;
	showTips(isShow, event);
	setHighLight(event);

	if (!isShow)
		QBTips::hideTip();
}

void InterestRateBondChart::initListMap()
{
	//国债，国开，非国开，地方政府债，总供给
	int nStart = 0;
	int nCount = 5;
	m_data.m_Map.clear();
	CRateBondUnit unit;
	unit.m_countArray[0] = INVALID_FLOAT;
	unit.m_countArray[1] = INVALID_FLOAT;
	unit.m_countArray[2] = INVALID_FLOAT;
	for (int j = nStart; j <= (nStart + nCount); ++j)
	{
		FIELDCOPY(unit.m_changeName, NewStringTable::strFixedIncomeRateBondFiltrCrd(j).toStdString().c_str());
		m_data.m_Map[unit.m_nIndex] = unit;
		++unit.m_nIndex;
	}
}

void InterestRateBondChart::getDistributionData(std::map<int, CRateBondList>* GovtBondIssuance, CRateBondMap& m_data)
{
	int bondtype = 0;//债券类型0-国债，1-国开，2-口行，3-农发，4-地方政府债，5-总供给
	double totalAmout = 0.0;
	CBondContainer& bc = CBondContainer::instance();

	std::map<int, CRateBondList>::iterator it = GovtBondIssuance->begin();
	for (; it != GovtBondIssuance->end(); ++it)
	{
		totalAmout = 0.0;
		std::list<int>::iterator itlist = it->second.m_List.begin();
		for (; itlist != it->second.m_List.end(); ++itlist)
		{
			double amount = 0.0;
			const CBondInfo& bi = bc.ElementAtR(*itlist);
			const CBondAuctionInfo* ai = bc.GetBondAuctionInfo(*itlist);

			if (ai)
			{
				amount = ai->GetActualAuctionAmount();
				if (amount < 1)	amount = ai->GetPlanedAuctionAmount();
			}
			if (amount < 1)amount = bi.GetActualIssueAmount();
			if (amount < 1)amount = bi.GetPlannedIssueAmount();
			/*if (SSS_LANGID_ENG_NEW == NewStringTable::GetLanguageID())
			{
				amount /= 100000;//billion
			}
			else */amount /= 10000;//亿

			//按债券类型分类
			if (bi.IsBondCountry())
			{
				bondtype = 0;
			}
			if (bi.IsBondGKZ())
			{
				bondtype = 1;
			}
			if (strcmp(bi.GetBondSubType(), "PSB") != 0 && strcmp(bi.GetIssuerCode(), "Z000189") == 0) {
				//口行
				bondtype = 2;
			}
			if (strcmp(bi.GetBondSubType(), "PSB") != 0 && strcmp(bi.GetIssuerCode(), "Z000207") == 0) {
				//农发
				bondtype = 3;
			}
			if (bi.IsBondLocal())
			{
				bondtype = 4;
			}
			totalAmout = totalAmout + amount;
			countToDistribution(bondtype, it->first, amount, m_data);
		}
		bondtype = 5;
		countToDistribution(bondtype, it->first, totalAmout, m_data);
	}
}

//按照债券类型来统计发行量
void InterestRateBondChart::countToDistribution(int nType, int week, double IssueAmount, CRateBondMap& data)
{
	switch (week)
	{
	case ratebondpanoramic::Type_laskweek:
	{
		(data.m_Map[nType]).m_countArray[0] = (data.m_Map[nType]).m_countArray[0] + IssueAmount;
		break;
	}
	case ratebondpanoramic::Type_thisweek:
	{
		(data.m_Map[nType]).m_countArray[1] = (data.m_Map[nType]).m_countArray[1] + IssueAmount;
		break;
	}
	case ratebondpanoramic::Type_nextweek:
	{
		(data.m_Map[nType]).m_countArray[2] = (data.m_Map[nType]).m_countArray[2] + IssueAmount;
		break;
	}
	default:
		break;
	}
}

void InterestRateBondChart::refresh(int dateType)
{
	if (m_week)
	{
		m_barsGroup->bars(0)->setPen(QPen(clrBarLastWeekNormal));
		m_barsGroup->bars(0)->setBrush(clrBarLastWeekNormal);
		
		m_barsGroup->bars(1)->setPen(QPen(clrBarThisWeekNormal));
		m_barsGroup->bars(1)->setBrush(clrBarThisWeekNormal);
		
		m_barsGroup->bars(2)->setPen(QPen(clrBarNextweekNormal, 1, Qt::DashLine));
		m_barsGroup->bars(2)->setBrush(clrBarNextweek);
	}
	else
	{
		m_barsGroup->bars(0)->setPen(QPen(clrBarLastMonthNormal));
		m_barsGroup->bars(0)->setBrush(clrBarLastMonthNormal);

		m_barsGroup->bars(1)->setPen(QPen(clrBarThisMonthNormal));
		m_barsGroup->bars(1)->setBrush(clrBarThisMonthNormal);

		m_barsGroup->bars(2)->setPen(QPen(clrBarNextMonthNormal, 1, Qt::SolidLine));
		m_barsGroup->bars(2)->setBrush(clrBarNextMonthNormal);
	}

	QVector<double> ticks1;
	QVector<double> data;
	ticks1 << 1 << 2 << 3 << 4 << 5 << 6;
	data << m_data.m_Map[0].m_countArray[0] << m_data.m_Map[1].m_countArray[0] << m_data.m_Map[2].m_countArray[0] << m_data.m_Map[3].m_countArray[0] << m_data.m_Map[4].m_countArray[0] << m_data.m_Map[5].m_countArray[0];
	m_barsGroup->bars(0)->setData(ticks1, data);

	data.clear();
	data << m_data.m_Map[0].m_countArray[1] << m_data.m_Map[1].m_countArray[1] << m_data.m_Map[2].m_countArray[1] << m_data.m_Map[3].m_countArray[1] << m_data.m_Map[4].m_countArray[1] << m_data.m_Map[5].m_countArray[1];
	m_barsGroup->bars(1)->setData(ticks1, data);

	data.clear();
	data << m_data.m_Map[0].m_countArray[2] << m_data.m_Map[1].m_countArray[2] << m_data.m_Map[2].m_countArray[2] << m_data.m_Map[3].m_countArray[2] << m_data.m_Map[4].m_countArray[2] << m_data.m_Map[5].m_countArray[2];
	m_barsGroup->bars(2)->setData(ticks1, data);
}

void InterestRateBondChart::setRange()
{
	float max = m_barsGroup->bars(0)->data()->at(5)->mainValue() > m_barsGroup->bars(1)->data()->at(5)->mainValue() ? m_barsGroup->bars(0)->data()->at(5)->mainValue() : m_barsGroup->bars(1)->data()->at(5)->mainValue();
	max = max > m_barsGroup->bars(2)->data()->at(5)->mainValue() ? max : m_barsGroup->bars(2)->data()->at(5)->mainValue();

	int array = 0;
	int maxInt = max;
	for (; maxInt > 10; ++array)
	{
		maxInt /= 10;
	}

	int range = 1;
	for (; array > 0; --array)
	{
		range *= 10;
	}

	int split = range / 2;
	if (split == 0)
		split = 1;

	int maxRange = maxInt * range;
	while (1)
	{
		if (maxRange > max || maxRange == 0)
			break;
		maxRange += split;
	}

	customPlot->yAxis->setRange(0, maxRange);
	customPlot->yAxis->ticker()->setTickCount(maxRange/split);
}

void InterestRateBondChart::showTips(bool& isShow, QMouseEvent* event)
{
	QPoint mousePos = event->pos();
	QString szText, szTips, szTemp, szPrice;
	QPointF barRect;

	for (int i = 0; i < 6; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			QRectF barRect = m_barsGroup->bars(j)->getBarRect(i + 1, m_barsGroup->bars(j)->data()->at(i)->mainValue());
			if (barRect.contains(mousePos))
			{
				isShow = true;
				szText = QString("%1").arg(customPlot->xAxis->tickVectorLabels()[i]);
				szTips.append(szText);

				szPrice = QString("%1").arg(m_data.m_Map[i].m_countArray[0], 0, 'f', 2, '0');
				szTemp = SSTools::PriceRemoveZero(szPrice, 0);
				if (szTemp == tr("0"))
					szTemp = tr("--");
				szText = QString("\n%1 %2").arg(m_week ? tr("上周") : tr("上月")).arg(szTemp);
				szTips.append(szText);

				szPrice = QString("%1").arg(m_data.m_Map[i].m_countArray[1], 0, 'f', 2, '0');
				szTemp = SSTools::PriceRemoveZero(szPrice, 0);
				if (szTemp == tr("0"))
					szTemp = tr("--");
				szText = QString("\n%1 %2").arg(m_week ? tr("本周") : tr("本月")).arg(szTemp);
				szTips.append(szText);

				szPrice = QString("%1").arg(m_data.m_Map[i].m_countArray[2], 0, 'f', 2, '0');
				szTemp = SSTools::PriceRemoveZero(szPrice, 0);
				if (szTemp == tr("0"))
					szTemp = tr("--");
				szText = QString("\n%1 %2").arg(m_week ? tr("下周") : tr("下月")).arg(szTemp);
				szTips.append(szText);

				std::vector<QBTipCustomItem> vctCustomItem;
				QBTipCustomItem item;
				item.clrNormal = QColor(223, 174, 76, 255);
				item.col = 1;

				for (int i = 0; i < 4; i++)
				{
					item.row = i + 1;
					vctCustomItem.push_back(item);
				}
				qb::QBTips::showText(event->screenPos().toPoint(), szTips, this, &vctCustomItem);
			}
		}
	}
}

void InterestRateBondChart::setHighLight(QMouseEvent* event)
{
	QPoint mousePos = event->pos();
	QString szText, szTips, szTemp, szPrice;
	QPointF barRect;
	QRectF lighterRect;
	double value;
	bool isLighter = false;

	for (int i = 0; i < 6; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			QRectF barRect = m_barsGroup->bars(j)->getBarRect(i + 1, m_barsGroup->bars(j)->data()->at(i)->mainValue());//m_data.m_Map[i].m_countArray[j]
			if (barRect.contains(mousePos))
			{
				isLighter = true;
				double lastValue = m_barsGroup->bars(0)->data()->at(i)->mainValue();
				double thisValue = m_barsGroup->bars(1)->data()->at(i)->mainValue();
				double nextValue = m_barsGroup->bars(2)->data()->at(i)->mainValue();

				QRectF lastRect = m_barsGroup->bars(0)->getBarRect(i + 1, lastValue);
				QRectF thisRect = m_barsGroup->bars(1)->getBarRect(i + 1, thisValue);
				QRectF nextRect = m_barsGroup->bars(2)->getBarRect(i + 1, nextValue);

				value = lastValue > thisValue ? lastValue : thisValue;
				lighterRect = lastValue > thisValue ? lastRect : thisRect;
				lighterRect = value > nextValue ? lighterRect : nextRect;
				lighterRect = QRectF(lastRect.left(), lighterRect.top(), lastRect.width() * 3, lighterRect.height());

				m_barsGroup->bars(0)->setLightRect(lighterRect);
				m_barsGroup->bars(1)->setLightRect(lighterRect);
				m_barsGroup->bars(2)->setLightRect(lighterRect);
			}
		}
	}

	if (!isLighter)
	{
		m_barsGroup->bars(0)->setLightRect(QRectF(0, 0, 0, 0));
		m_barsGroup->bars(1)->setLightRect(QRectF(0, 0, 0, 0));
		m_barsGroup->bars(2)->setLightRect(QRectF(0, 0, 0, 0));
	}

	customPlot->replot();
}